<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://www.freedom.com/oldsong/security" prefix="oldsong" %>
<script type="text/javascript">
// Pagination script
var Page = new Object();
Page.currentPage = 1;
Page.lastPage = 1;

Page.goFirstPage = function(){
    if (Page.currentPage > 1) {
        Page.goToPage(1);
    }
}

Page.goPrePage = function(){
    if (Page.currentPage > 1) {
        Page.goToPage(--Page.currentPage);
    }  
}
Page.goNextPage = function(){
    if (Page.currentPage < Page.lastPage) {
        Page.goToPage(++Page.currentPage);
        
    }
}
Page.goLastPage = function(){
    if (Page.currentPage < Page.lastPage) {
        Page.goToPage(Page.lastPage);
    }
}

Page.goToPage = function(pageNum){
    $j("#page-form>input[name=currentPage]").val(pageNum);
    $j("#page-form").submit();    
}

Page.init = function(){
   	Page.lastPage = parseInt($j("#totalPageNum").val());
    if (Page.lastPage <= 1) {
        $j("#page-div").hide();
    }
    else {
        $j("#page-div").show();
    }  
    Page.currentPage = parseInt($j("#page-form>input[name=currentPage]").val());
    var page = $j("#ppageId");
    page.find("option").remove();
    if ($j("#token-fix-back").val() == "true") { // fix back button
    	$j("#token-fix-back").val(Page.currentPage);
	}
	else {
    	Page.currentPage = $j("#token-fix-back").val();
	}
    for (var i = 1; i <= Page.lastPage; i++) {
        if (i == Page.currentPage ) {
            page.append("<option value='" + (i) + "'  selected='selected'> " + (i) + " </option>");
        }
        else {
            page.append("<option value='" + i + "'>" + i + "</option>");
        }
    }
	if (Page.currentPage <= 1) {
		$j("#page-div a:lt(2)").addClass("disable");
	}else {
		$j("#page-div a:lt(2)").removeClass("disable");
	}
	if (Page.currentPage >= Page.lastPage) {
		$j("#page-div a:gt(1)").addClass("disable");
	}else {
		$j("#page-div a:gt(1)").removeClass("disable");
	}
	var low = parseInt($j("#pageSize").val()) * (Page.currentPage  - 1) + 1;
	var high = low + parseInt($j("#count").val()) -1;
	$j("#detail-data").text(low + " - " + high);
} // end of Pagination script


$j(function () {
	Page.init();
});

</script>
<div class="pgn" id="page-div" style="display: none;">
	<span class="pgn-info"><b id="detail-data"></b>&nbsp;of <b id="total-data"><s:property value="totalCount" />&nbsp;</b></span>
	<a class="firstpage disable" title="First page" href="#" onclick="javascript:Page.goFirstPage();">
	</a>
	<a class="previouspage disable" title="Previous" href="#" onclick="javascript:Page.goPrePage();">
	</a>
	<select name="ppageId" id="ppageId" onchange="javascript:Page.goToPage(this.value);">
		<option><<oldsong:I18N key="current"/></option>
	</select>
	<a class="nextpage" title="Next" href="#" onclick="javascript:Page.goNextPage();">
	</a>
	<a class="lastpage" title="Last page" href="#" onclick="javascript:Page.goLastPage();">
	</a>
</div>
<input type="hidden" name="token-fix-back" id="token-fix-back" value="true" />
<form action="" id="page-form" method="post">
	<input type="hidden" value="<s:property value="pageResult.totalCount"/>" id="totalCount" name="totalCount"/>
	<input type="hidden" value="<s:property value="pageResult.currentPage"/>" id="currentPage" name="currentPage"/>
	<input type="hidden" value="<s:property value="pageResult.pageCount"/>" id="pageCount"  name="pageCount"/>
	<input type="hidden" value="<s:property value="pageResult.pageSize"/>" id="pageSize" name="pageSize"/>
	<input type="hidden" value="<s:property value="pageResult.count"/>" id="count" name="count"/>
	<input type="hidden" value="<s:property value="pageResult.sort"/>" id="sort" name="sort"/>
	<input type="hidden" value="<s:property value="orgId"/>" name="orgId"/>
</form>
<script type="text/javascript">
if (typeof Sort != 'undefined') {
	 Sort.init();
}
</script>


